<?php

require_once '../core.php';

$allowed_types = array("image/pjpeg","image/jpeg","image/gif","x-png");

if(isset($_POST['submit']))
{
    require_once '../Models/ClassUtilisateur.php';
    
    $sNom = $_POST['nom'];
    $sPrenom = $_POST['prenom'];
    $sPassword = $_POST['mdp'];
    $sMail= $_POST['email'];
    $sSexe= $_POST['sexe'];
    $sDateNaissance = strtotime($_POST['naissance']);
    $sLienPhoto = "";
    
    if(isset($_FILES["avatar"]))
    {
         $path = '../';
         $dossier = 'avatar/';
         $guid = uniqid();
         $fichier = basename($_FILES['avatar']['name']);
         if(in_array($_FILES['avatar']['type'], $allowed_types))
         {
             $ext = strrchr($_FILES['avatar']['name'],'.');
             $filename = $dossier . $guid . $ext;
             move_uploaded_file($_FILES['avatar']['tmp_name'], $path . $filename);
             $sLienPhoto = "http://" . SITE_FOLDER . $filename;
         }
    }
    
    $data = ClassUtilisateur::AddUtilisateur($sNom, $sPrenom, $sPassword, $sMail, $sDateNaissance, $sLienPhoto, $sSexe);
    
    if($data != false)
        ClassUtilisateur::Logon($sMail, $sPassword);
    
    header("location:../index.php");
}
 else {
    header("location:../Templates/inscription.html");
}

?>
